import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_card.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_row_title.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/core/utils/file_util.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/execute_entity.dart';

/// 安全交底
class SecurityDisclosurePage extends StatelessWidget {
  const SecurityDisclosurePage({super.key});

  // 交底类型 0：安全交底人 1：接受交底人 2：监护人
  String _str(int? i) {
    switch (i) {
      case 0:
        return '安全交底人';
      case 1:
        return '接受交底人';
      case 2:
        return '监护人';
      default:
        return '';
    }
  }

  @override
  Widget build(BuildContext context) {
    final List<ExecuteTicketDiscloseList> ticketDiscloseList = Get.arguments as List<ExecuteTicketDiscloseList>;
    // 附件信息
    final List<String> attachmentList = [];
    // 安全交底人签名
    final List<String> safetyDisclosureList = [];
    // 接收交底人签名
    final List<String> receivingDisclosureList = [];
    // 接收交底几率
    String discloseVideo = '';
    for (var bean in ticketDiscloseList) {
      attachmentList.addAll(bean.discloseFile!);
      if (bean.discloseType == 0) {
        safetyDisclosureList.addAll(bean.discloseUserSign!);
      }
      if (bean.discloseType == 1) {
        receivingDisclosureList.addAll(bean.discloseUserSign!);
        discloseVideo = bean.discloseVideo!;
      }
    }

    return Scaffold(
      backgroundColor: AppColors.bg_color_grey,
      appBar: CustomAppBar(
        titleText: '安全交底内容',
      ),
      body: Container(
        padding: EdgeInsets.all(16.w),
        child: ListView(
          children: [
            CustomCard(
              title: '安全交底',
              content: Container(
                alignment: AlignmentDirectional.centerStart,
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Visibility(
                      visible: attachmentList.isNotEmpty,
                      child: Column(
                        children: [
                          Text(
                            '交底附件',
                            style: TextStyle(
                              fontSize: 13.sp,
                              color: AppColors.font_color_black,
                            ),
                          ),
                          ...attachmentList
                              .map((e) => Container(
                                    margin: EdgeInsets.only(top: 10.w),
                                    decoration: const BoxDecoration(
                                      color: Color(0x1A5C6DFF),
                                    ),
                                    child: Row(
                                      children: [
                                        AppGaps.hGap10,
                                        Expanded(
                                          child: Text(
                                            e,
                                            overflow: TextOverflow.ellipsis,
                                            style: TextStyle(
                                              fontSize: 12.sp,
                                              color: const Color(0xFF587DF5),
                                            ),
                                          ),
                                        ),
                                        Container(
                                          width: 80.w,
                                          padding: EdgeInsets.only(left: 12.w, top: 5.w, bottom: 5.w),
                                          color: const Color(0x3F587DF5),
                                          child: Text(
                                            '点击查看',
                                            style: TextStyle(
                                              fontSize: 12.sp,
                                              color: const Color(0xFF587DF5),
                                            ),
                                          ),
                                        )
                                      ],
                                    ),
                                  ).click(() {
                                    FileUtils.openFile(e);
                                  }))
                              ,
                        ],
                      ),
                    ),
                    Visibility(
                      visible: discloseVideo.isNotEmpty,
                      child: Container(
                        height: 170.w,
                        width: double.infinity,
                        margin: EdgeInsets.only(top: 10.w),
                        decoration: BoxDecoration(
                          color: Colors.black,
                          borderRadius: BorderRadius.circular(6.w),
                        ),
                        child: Icon(
                          Icons.play_circle,
                          size: 40.w,
                          color: Colors.white,
                        ),
                      ).clickOnce(() {
                        FileUtils.openFile(discloseVideo);
                      }),
                    ),
                    AppGaps.vGap10,
                    CustomRowTitle(
                        title: '安全交底人：',
                        contentWidget: Wrap(
                          // spacing: 2.w, // 主轴(水平)方向间距
                          runSpacing: 10.w, // 纵轴（垂直）方向间距
                          direction: Axis.horizontal,
                          children: safetyDisclosureList.map<Widget>((item) {
                            return Container(
                              margin: EdgeInsets.only(top: 8.w, right: 8.w),
                              width: 76.w,
                              height: 36.w,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(4.w),
                                  color: Colors.white,
                                  border: Border.all(
                                    color: const Color(0xFFEFF2F6),
                                    width: 1,
                                  ),
                                  image: DecorationImage(
                                    image: NetworkImage(Interface.fileUrl + item),
                                  )),
                            ).clickShowLarge(url: Interface.fileUrl + item);
                          }).toList(),
                        ),
                        content: ''),
                    AppGaps.vGap10,
                    CustomRowTitle(
                        title: '接收交底人：',
                        contentWidget: Wrap(
                          // spacing: 2.w, // 主轴(水平)方向间距
                          runSpacing: 10.w, // 纵轴（垂直）方向间距
                          direction: Axis.horizontal,
                          children: receivingDisclosureList.map<Widget>((item) {
                            return Container(
                              margin: EdgeInsets.only(top: 8.w, right: 8.w),
                              width: 76.w,
                              height: 36.w,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(4.w),
                                  color: Colors.white,
                                  border: Border.all(
                                    color: const Color(0xFFEFF2F6),
                                    width: 1,
                                  ),
                                  image: DecorationImage(
                                    image: NetworkImage(Interface.fileUrl + item),
                                  )),
                            ).clickShowLarge(url: Interface.fileUrl + item);
                          }).toList(),
                        ),
                        content: ''),
                  ],
                ),
              ),
            )
          ],
        ),

        // ListView.separated(
        // itemCount: ticketDiscloseList.length,
        // itemBuilder: (context, index) {
        //   final item = ticketDiscloseList[index];
        //   return CustomCard(
        //     title: '安全交底',
        //     content: Column(
        //       children: [
        //         Visibility(
        //           visible: item.discloseType != 0 && item.discloseFile!.isNotEmpty,
        //           child: Column(
        //             children: [
        //               Row(
        //                 children: [
        //                   Text(
        //                     '文件',
        //                     style: TextStyle(
        //                       fontSize: 13.sp,
        //                       color: AppColors.font_color_black,
        //                     ),
        //                   ),
        //                 ],
        //               ),
        //               AppGaps.vGap10,
        //               ...item.discloseFile!
        //                   .map((e) =>
        //                   Container(
        //                     decoration: const BoxDecoration(
        //                       color: Color(0x1A5C6DFF),
        //                     ),
        //                     child: Row(
        //                       children: [
        //                         AppGaps.hGap10,
        //                         Expanded(
        //                           child: Text(
        //                             e,
        //                             overflow: TextOverflow.ellipsis,
        //                             style: TextStyle(
        //                               fontSize: 12.sp,
        //                               color: const Color(0xFF587DF5),
        //                             ),
        //                           ),
        //                         ),
        //                         const Spacer(),
        //                         Container(
        //                           width: 80.w,
        //                           padding: EdgeInsets.only(left: 12.w, top: 5.w, bottom: 5.w),
        //                           color: const Color(0x3F587DF5),
        //                           child: Text(
        //                             '点击查看',
        //                             style: TextStyle(
        //                               fontSize: 12.sp,
        //                               color: const Color(0xFF587DF5),
        //                             ),
        //                           ),
        //                         )
        //                       ],
        //                     ),
        //                   ).click(() {
        //                     FileUtils.openFile(e);
        //                   }))
        //                   .toList(),
        //               AppGaps.vGap10,
        //             ],
        //           ),
        //         ),
        //         Visibility(
        //           visible: item.discloseVideo!.isNotEmpty,
        //           child: Container(
        //             height: 170.w,
        //             width: double.infinity,
        //             margin: EdgeInsets.only(bottom: 10.w),
        //             decoration: BoxDecoration(
        //               color: Colors.black,
        //               borderRadius: BorderRadius.circular(6.w),
        //             ),
        //             child: Icon(
        //               Icons.play_circle,
        //               size: 40.w,
        //               color: Colors.white,
        //             ),
        //           ).clickOnce(() {
        //             FileUtils.openFile(item.discloseVideo.toString());
        //           }),
        //         ),
        //         Container(
        //           decoration: BoxDecoration(
        //             color: const Color(0xFFF7F7FB),
        //             borderRadius: BorderRadius.circular(6.w),
        //             border: Border.all(
        //               color: const Color(0xFFEBEDF0),
        //               width: 1.w,
        //             ),
        //           ),
        //           child: Column(
        //               children: item.discloseUserSign!
        //                   .map((e) =>
        //                   CustomRowTitle(
        //                       title: '${_str(item.discloseType)}：',
        //                       contentWidget: Container(
        //                         alignment: Alignment.centerRight,
        //                         child: Image.network(height: 30.w, Interface.fileUrl + e).clickShowLarge(url: Interface.fileUrl + e),
        //                       ),
        //                       content: ''))
        //                   .toList()),
        //         )
        //       ],
        //     ),
        //   );
        // },
        // separatorBuilder: (context, index) {
        //   return SizedBox(height: 16.w);
        // })
      ),
    );
  }
}
